﻿using ESCDB.DB;
using Oracle.ManagedDataAccess.Client;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace WQPda
{
    /// <summary>
    /// pda 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消注释以下行。 
    // [System.Web.Script.Services.ScriptService]
    public class pda : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }
        public static void HandleException(Exception ex)
        {

            //记录日志
            string path = System.AppDomain.CurrentDomain.BaseDirectory;
            if (!System.IO.Directory.Exists(path + @"\Log"))
            {
                System.IO.Directory.CreateDirectory(path + @"\Log");
            }
            DateTime now = DateTime.Now;
            string logpath = string.Format(@"\Log\fatal_{0}{1}{2}.log", now.Year, now.Month, now.Day);
            System.IO.File.AppendAllText(path + logpath, string.Format("\r\n----------------------{0}--------------------------\r\n", now.ToString("yyyy-MM-dd HH:mm:ss")));
            System.IO.File.AppendAllText(path + logpath, ex.Message);
            System.IO.File.AppendAllText(path + logpath, "\r\n");
            System.IO.File.AppendAllText(path + logpath, ex.StackTrace);
            System.IO.File.AppendAllText(path + logpath, "\r\n");
            System.IO.File.AppendAllText(path + logpath, "\r\n----------------------footer--------------------------\r\n");
        }
        public class UserInfo
        {
            public string ORG_CODE { get; set; }//廠區
            public string USER_ID { get; set; }//操作人員ID
            public string USER_NAME { get; set; }//操作人員
            public string DESCRIPTION { get; set; }//工號
            public string OUT_STATUS { get; set; }//工號
            public string OUT_MESSAGE { get; set; }//工號
        }

        //登录
        [WebMethod]
        public UserInfo Login(string username,string password)
        {
            UserInfo r = new UserInfo();
            try
            {
                WQEntities context = new WQEntities();
                string spName = "APPS.RL_CHK_PDA_USER"; // 存储过程名称
                string OUT_STATUS = "";
                string OUT_MESSAGE = "";
                using (var cmd = context.Database.Connection.CreateCommand())
                {
                    cmd.Connection.Open();
                    cmd.CommandText = spName;
                    cmd.CommandType = CommandType.StoredProcedure;

                    // 输入参数
                    cmd.Parameters.Add(new OracleParameter("IN_USER", username));
                    cmd.Parameters.Add(new OracleParameter("IN_PASSWD", password));

                    // 输出参数
                    var outStatus = new OracleParameter("OUT_STATUS", OracleDbType.Varchar2, 100)
                    {
                        Direction = ParameterDirection.Output
                    };
                    cmd.Parameters.Add(outStatus);

                    var outMessage = new OracleParameter("OUT_MESSAGE", OracleDbType.Varchar2, 4000)
                    {
                        Direction = ParameterDirection.Output
                    };

                    cmd.Parameters.Add(outMessage);
                    cmd.ExecuteNonQuery();
                    OUT_STATUS = cmd.Parameters["OUT_STATUS"].Value.ToString();
                    OUT_MESSAGE = cmd.Parameters["OUT_MESSAGE"].Value.ToString();
                }
                

                if (OUT_STATUS == "S")
                {
                    var sqlResult = context.Database.SqlQuery<UserInfo>("select *  from RL_PDA_USER where user_name='" + username + "'");
                    foreach (var order in sqlResult)
                    {
                        r = order;
                    }
                }
                r.OUT_STATUS = OUT_STATUS;
                r.OUT_MESSAGE = OUT_MESSAGE;
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
            return r;
        }
        public class BQView
        {
            public string BQ { get; set; }
            public string REEL_UNION { get; set; }
            
        }


        public class rl_pda_wip_to_inv
        {
            public string ORG_CODE { get; set; }//廠區
            public string ITEM_TYPE { get; set; }//物料類型:成品FG,散料STT
            public string LOCATION_NUMBER { get; set; }//上架單號
            public int LOCATOR_ID { get; set; }//儲位ID
            public string TRANSACTION_SOURCE_NAME { get; set; }//工單號
            public string LOT_NUMBER { get; set; }//批號
            public string ITEM_NAME { get; set; }//料號
            public string PART_TYPE { get; set; }//型別
            public string TOLERATE_VALUE { get; set; }//容差
            public string RESISTANCE { get; set; }//阻值
            public string RESISTANCE_VALUE_R { get; set; }//R值
            public string CUSTOMER_LOT { get; set; }//客戶批號
            public string RELEASE_FLAG { get; set; }//N為工單入庫,C為PDA已檢驗過,Y消單儲位釋放
            public string SUBINVENTORY_CODE { get; set; }//倉庫
            public string SEGMENT1 { get; set; }//儲位架
            public string SEGMENT2 { get; set; }//儲位層
            public string SEGMENT3 { get; set; }//儲位
            public DateTime? TRANSACTION_DATE { get; set; }//工單入庫日期
            public string STD_KPCS { get; set; }//基本包裝量
            public string TRANSACTION_QUANTITY { get; set; }//入庫量
            public int REEL { get; set; }//入庫卷數
            public string ATTRIBUTE1 { get; set; }//記錄唯一刷條碼
            public string ATTRIBUTE2 { get; set; }//記錄唯一刷條碼
            public string ATTRIBUTE3 { get; set; }//記錄唯一刷條碼
            public string ATTRIBUTE4 { get; set; }//記錄唯一刷條碼
            public string ATTRIBUTE5 { get; set; }//記錄唯一刷條碼
            public string ATTRIBUTE6 { get; set; }//記錄唯一刷條碼
            public string ATTRIBUTE7 { get; set; }//記錄唯一刷條碼
            public string ATTRIBUTE8 { get; set; }//記錄唯一刷條碼
            public string ATTRIBUTE9 { get; set; }//記錄唯一刷條碼
            public string ATTRIBUTE10 { get; set; }//記錄唯一刷條碼
            public string USER_ID { get; set; }//操作人員ID
            public string USER_NAME { get; set; }//操作人員
            public string CARD_NUM { get; set; }//工號
            public DateTime? CREATION_DATE { get; set; }//創建日期
            public DateTime? LAST_UPDATE { get; set; }//更新檢驗日期
            public string WIP_LINE_ID { get; set; }//rl_pda_wip_to_inv_s.nextval
            public string REEL_ID { get; set; }//唯一碼.nextval
            public string MANUAL_TYPE { get; set; }//默認Ｎ，Ｙ為移倉特殊情況人工檢查
            public string MANUAL_USER_ID { get; set; }//
            public string MANUAL_DATE { get; set; }//
            public decimal? TotalREEL { get; set; }//
            public string REEL_UNIONList { get; set; }//
        }

        public class UserState
        {
            public string v_status { get; set; }
            public string v_message { get; set; }
            
        }

        //根据上架单获取详细信息
        [WebMethod]
        public List<rl_pda_wip_to_inv> Get_rl_pda_wip_to_inv_by_LOCATION_NUMBER(string LOCATION_NUMBER, string ORG_CODE)
        {
            WQEntities context = new WQEntities();
            List<rl_pda_wip_to_inv> List = new List<rl_pda_wip_to_inv>();
            try
            {
                var sqlResult = context.Database.SqlQuery<rl_pda_wip_to_inv>("select r.*,rowid from rl_pda_wip_to_inv r where r.ORG_CODE="+ ORG_CODE+" and r.LOCATION_NUMBER=" + LOCATION_NUMBER);
                foreach (var order in sqlResult)
                {
                    rl_pda_wip_to_inv b = order;
                    List.Add(b);
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
            return List;
        }
        //获取上架單号
        [WebMethod]
        public List<string> Get_rl_pda_wip_to_inv_LOCATION_NUMBER(string ORG_CODE)
        {
            WQEntities context = new WQEntities();
            List<string> List = new List<string>();
            try
            {
                var sqlResult = context.Database.SqlQuery<string>("select distinct LOCATION_NUMBER from rl_pda_wip_to_inv where ORG_CODE=" + ORG_CODE);
                foreach (var order in sqlResult)
                {
                    List.Add(order);
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
            return List;
        }
        //上架.扫描上架
        [WebMethod]
        public string Update_rl_pda_wip_to_inv(string LOCATION_NUMBER, int LOCATOR_ID,string REEL,string BQ, string REEL_UNION, string userid, string ORG_CODE)
        {
            //var a = context1.wip_to_inv_record.ToList();
            //int count1 = context1.Database.ExecuteSqlCommand("UPDATE wip_to_inv_record SET LOT_NUMBER ='R2516Q025C3' WHERE ID  = 1");
            //int count = context.Database.ExecuteSqlCommand("UPDATE rl_pda_wip_to_inv set LOT_NUMBER ='R2516Q025C2' where LOCATOR_ID = 338717");
            //context.Database.ExecuteSqlCommand("UPDATE rl_pda_wip_to_inv SET LOT_NUMBER  = {0} WHERE LOCATOR_ID = {1}", "R2516Q025C1", 338705);
            //context.Database.ExecuteSqlCommand("UPDATE rl_pda_wip_to_inv SET LOT_NUMBER ='R2516Q025C1' WHERE LOCATOR_ID  = @author", new OracleParameter("@author",338705));

            WQEntities context = new WQEntities();
            WQEntities1 PDA = new WQEntities1();
            try
            {
                var menu = GetMenu(userid, ORG_CODE);
                if (menu.IndexOf("PDAF0001,") < 0)
                {
                    return "false:當前用戶沒有操作權限";
                }
                string NowDate = getTime();
                //先看下是否有人保存了数据，有的话就不让再保存
                //var nowvalue = PDA.wip_to_inv_record.FirstOrDefault(x => x.LOCATION_NUMBER == LOCATION_NUMBER && x.LOCATOR_ID == LOCATOR_ID && x.isDelete == false && x.State == true);
                //if (nowvalue != null)
                //    return "false:重複提交儲位";
                //else
                //{
                    int count = context.Database.ExecuteSqlCommand("UPDATE rl_pda_wip_to_inv SET RELEASE_FLAG  = 'C',USER_ID=:p0,LAST_UPDATE=:p1 WHERE RELEASE_FLAG = 'N' and LOCATION_NUMBER=:p2 and LOCATOR_ID = :p3 and ORG_CODE = :p4", new[] { new OracleParameter(":p0", userid), new OracleParameter(":p1", NowDate), new OracleParameter(":p2", LOCATION_NUMBER), new OracleParameter(":p3", LOCATOR_ID), new OracleParameter(":p4", ORG_CODE) });

                    var sqlResult = context.Database.SqlQuery<rl_pda_wip_to_inv>("select r.*,rowid from rl_pda_wip_to_inv r where r.LOCATION_NUMBER=" + LOCATION_NUMBER+ " and r.LOCATOR_ID="+ LOCATOR_ID + " and r.ORG_CODE=" + ORG_CODE);
                    rl_pda_wip_to_inv b = sqlResult.First();
                    wip_to_inv_record v = new wip_to_inv_record();
                    v.ORG_CODE = b.ORG_CODE;
                    v.LOCATION_NUMBER = LOCATION_NUMBER;
                    v.LOT_NUMBER = b.LOT_NUMBER;
                    v.CUSTOMER_LOT = b.CUSTOMER_LOT;
                    v.ITEM_NAME = b.ITEM_NAME;
                    v.LOCATOR_ID = LOCATOR_ID;
                    v.SUBINVENTORY_CODE = b.SUBINVENTORY_CODE;
                    v.SEGMENT1 = b.SEGMENT1;
                    v.SEGMENT2 = b.SEGMENT2;
                    v.SEGMENT3 = b.SEGMENT3;
                    v.STD_KPCS = b.STD_KPCS;
                    v.TRANSACTION_QUANTITY = b.TRANSACTION_QUANTITY;
                    v.REEL = b.REEL;
                    v.BQ = BQ;
                    v.REEL_UNION = REEL_UNION;
                    v.ACTUAL_REEL = int.Parse(REEL);
                    v.State = count>=1?true:false;
                    v.isDelete = false;
                    v.creater = userid;
                    v.createTime = DateTime.Now;
                    v.updater = userid;
                    v.updateTime = DateTime.Now;
                    PDA.wip_to_inv_record.Add(v);
                    PDA.SaveChanges();
                    if (v.State==true)
                        return "true";
                    else
                        return "false:更新狀態失敗,請刷新頁面查看當前狀態";
                //}
                
            }
            catch (Exception ex)
            {
                HandleException(ex);
                return "false:执行错误";
            }
        }
        [WebMethod]
        public string Update_rl_pda_wip_to_inv_PL(string LOCATION_NUMBER,string LOCATOR_IDs, string userid, string ORG_CODE)
        {
            WQEntities context = new WQEntities();
            WQEntities1 PDA = new WQEntities1();
            try
            {
                var menu = GetMenu(userid, ORG_CODE);
                if (menu.IndexOf("PDAF0001,") < 0)
                {
                    return "false:當前用戶沒有操作權限";
                }
                string NowDate = getTime();
                List<long?> LOCATOR_IDList = new List<long?>();
                foreach (var l in LOCATOR_IDs.Split(','))
                {
                    if (!string.IsNullOrEmpty(l))
                        LOCATOR_IDList.Add(long.Parse(l));
                }
                //先看下是否有人保存了数据，有的话就不让再保存
                //var nowvalue = PDA.wip_to_inv_record.FirstOrDefault(x => x.LOCATION_NUMBER == LOCATION_NUMBER && LOCATOR_IDList.Contains(x.LOCATOR_ID) && x.isDelete == false && x.State == true);
                //if (nowvalue != null)
                //    return "false:重複提交儲位";
                //else
                //{
                    int count = context.Database.ExecuteSqlCommand("UPDATE rl_pda_wip_to_inv SET RELEASE_FLAG  = 'C',USER_ID="+userid+ ",LAST_UPDATE='" + NowDate + "' WHERE RELEASE_FLAG  = 'N' and LOCATION_NUMBER=" + LOCATION_NUMBER + " and LOCATOR_ID in (" + LOCATOR_IDs.Substring(0, LOCATOR_IDs.Length - 1) + ") and r.ORG_CODE = " + ORG_CODE);
                var sqlResult = context.Database.SqlQuery<rl_pda_wip_to_inv>("select r.*,rowid from rl_pda_wip_to_inv r where r.LOCATION_NUMBER=" + LOCATION_NUMBER + " and r.LOCATOR_ID in (" + LOCATOR_IDs.Substring(0, LOCATOR_IDs.Length - 1)+ ") and r.ORG_CODE = " + ORG_CODE);
                    foreach (var b in sqlResult)
                    {
                        wip_to_inv_record v = new wip_to_inv_record();
                        v.ORG_CODE = b.ORG_CODE;
                        v.LOCATION_NUMBER = LOCATION_NUMBER;
                        v.LOT_NUMBER = b.LOT_NUMBER;
                        v.ITEM_NAME = b.ITEM_NAME;
                        v.LOCATOR_ID = b.LOCATOR_ID;
                    v.CUSTOMER_LOT = b.CUSTOMER_LOT;
                    v.SUBINVENTORY_CODE = b.SUBINVENTORY_CODE;
                        v.SEGMENT1 = b.SEGMENT1;
                        v.SEGMENT2 = b.SEGMENT2;
                        v.SEGMENT3 = b.SEGMENT3;
                        v.STD_KPCS = b.STD_KPCS;
                        v.TRANSACTION_QUANTITY = b.TRANSACTION_QUANTITY;
                        v.REEL = b.REEL;
                        v.ACTUAL_REEL = b.REEL;
                        v.State = count >= 1 ? true : false;
                        v.isDelete = false;
                        v.creater = userid;
                        v.createTime = DateTime.Now;
                        v.updater = userid;
                        v.updateTime = DateTime.Now;
                        PDA.wip_to_inv_record.Add(v);
                    }
                    PDA.SaveChanges();
                    if (count >= 1)
                        return "true";
                    else
                        return "false:更新狀態失敗,請刷新頁面查看當前狀態";
                //}

            }
            catch (Exception ex)
            {
                HandleException(ex);
                return "false:执行错误";
            }
        }
        //单笔上架
        [WebMethod]
        public List<rl_pda_wip_to_inv> Get_rl_pda_wip_to_inv_by_LOCATION_NUMBERDB(string LOCATION_NUMBER, string ORG_CODE)
        {
            WQEntities context = new WQEntities();
            WQEntities1 PDA = new WQEntities1();
            List<rl_pda_wip_to_inv> List = new List<rl_pda_wip_to_inv>();
            try
            {
                var sqlResult = context.Database.SqlQuery<rl_pda_wip_to_inv>("select r.*,rowid from rl_pda_wip_to_inv r where r.ORG_CODE=" + ORG_CODE + " and r.LOCATION_NUMBER=" + LOCATION_NUMBER);
                foreach (var order in sqlResult)
                {
                    rl_pda_wip_to_inv b = order;
                    b.TotalREEL = 0;
                    b.REEL_UNIONList = "";
                    var record = PDA.wip_to_inv_record.Where(x => x.LOCATION_NUMBER == order.LOCATION_NUMBER && x.LOCATOR_ID == order.LOCATOR_ID && x.isDelete == false && x.State == true).ToList();
                    foreach (var r in record)
                    {
                        b.TotalREEL += r.ACTUAL_REEL;
                        b.REEL_UNIONList += r.REEL_UNION+",";
                    }
                    List.Add(b);
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
            return List;
        }
        [WebMethod]
        public string Update_rl_pda_wip_to_invDB(string LOCATION_NUMBER, int LOCATOR_ID, List<BQView> BQList, string userid, string ORG_CODE)
        {
            WQEntities context = new WQEntities();
            WQEntities1 PDA = new WQEntities1();
            try
            {
                var menu = GetMenu(userid, ORG_CODE);
                if (menu.IndexOf("PDAF0001,") < 0)
                {
                    return "false:當前用戶沒有操作權限";
                }
                string NowDate = getTime();
                //先看下是否有人保存了数据，有的话就不让再保存
                List<string> BQREEL_UNIONList = BQList.Select(x => x.REEL_UNION).ToList();
                var nowvalue = PDA.wip_to_inv_record.Where(x => BQREEL_UNIONList.Contains(x.REEL_UNION) && x.isDelete == false && x.State == true).ToList();
                if (nowvalue.Count>0)
                {
                    string cf = "";
                    foreach (var n in nowvalue)
                        cf += n.REEL_UNION + ";";
                    return "false:重複提交标签：" + cf;
                }
                else
                {
                    //如果卷数足够，就去修改状态，否则不改
                    var record = PDA.wip_to_inv_record.Where(x => x.LOCATION_NUMBER == LOCATION_NUMBER && x.LOCATOR_ID == LOCATOR_ID && x.isDelete == false && x.State == true).ToList();
                    decimal? total = BQList.Count();
                    foreach (var r in record)
                        total += r.ACTUAL_REEL;
                    var sqlResult = context.Database.SqlQuery<rl_pda_wip_to_inv>("select r.*,rowid from rl_pda_wip_to_inv r where r.LOCATION_NUMBER=" + LOCATION_NUMBER + " and r.LOCATOR_ID=" + LOCATOR_ID + " and r.ORG_CODE=" + ORG_CODE);
                    rl_pda_wip_to_inv b = sqlResult.First();

                    if (total == b.REEL)
                    {
                        int count = context.Database.ExecuteSqlCommand("UPDATE rl_pda_wip_to_inv SET RELEASE_FLAG  = 'C',USER_ID=:p0,LAST_UPDATE=:p1 WHERE RELEASE_FLAG = 'N' and LOCATION_NUMBER=:p2 and LOCATOR_ID = :p3 and ORG_CODE = :p4", new[] { new OracleParameter(":p0", userid), new OracleParameter(":p1", NowDate), new OracleParameter(":p2", LOCATION_NUMBER), new OracleParameter(":p3", LOCATOR_ID), new OracleParameter(":p4", ORG_CODE) });
                        if (count == 0)
                            return "false:更新狀態失敗,請刷新頁面查看當前狀態";
                    }
                    foreach (var bq in BQList)
                    {
                        wip_to_inv_record v = new wip_to_inv_record();
                        v.ORG_CODE = b.ORG_CODE;
                        v.LOCATION_NUMBER = LOCATION_NUMBER;
                        v.LOT_NUMBER = b.LOT_NUMBER;
                        v.ITEM_NAME = b.ITEM_NAME;
                        v.CUSTOMER_LOT = b.CUSTOMER_LOT;
                        v.LOCATOR_ID = LOCATOR_ID;
                        v.SUBINVENTORY_CODE = b.SUBINVENTORY_CODE;
                        v.SEGMENT1 = b.SEGMENT1;
                        v.SEGMENT2 = b.SEGMENT2;
                        v.SEGMENT3 = b.SEGMENT3;
                        v.STD_KPCS = b.STD_KPCS;
                        v.TRANSACTION_QUANTITY = b.TRANSACTION_QUANTITY;
                        v.REEL = b.REEL;
                        v.BQ = bq.BQ;
                        v.REEL_UNION = bq.REEL_UNION;
                        v.ACTUAL_REEL = 1;
                        v.State = true;
                        v.isDelete = false;
                        v.creater = userid;
                        v.createTime = DateTime.Now;
                        v.updater = userid;
                        v.updateTime = DateTime.Now;
                        PDA.wip_to_inv_record.Add(v);
                    }
                    PDA.SaveChanges();
                    return "true";
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
                return "false:执行错误";
            }
        }




        public class rl_pda_pick_pulloff
        {
            public string ORG_CODE { get; set; }//廠區
            public string ITEM_TYPE { get; set; }//物料類型:成品FG,散料STT
            public string CUSTOMER_NUMBER { get; set; }//客戶編號
            public string CUSTOMER_NAME_PHONETIC { get; set; }//客戶簡稱
            public string SHIP_TO_NUMBER { get; set; }//送貨地址
            public string PRINT_CODE { get; set; }//撿貨列印碼
            public string DELIVERY_NAME { get; set; }//出貨單號
            public string LOT_NUMBER { get; set; }//批號
            public string ITEM_NAME { get; set; }//料號
           
            public string PART_TYPE { get; set; }//型別
            public string TOLERATE_VALUE { get; set; }//容差
            public string RESISTANCE { get; set; }//阻值
            public string RESISTANCE_VALUE_R { get; set; }//R值
            public string OUTER_NUMBER { get; set; }//外箱
            public string RELEASE_LOC_FLAG { get; set; }//撿貨狀態,Y為已撿未下架,C為撿貨下架檢驗,為N為撿貨下架
            public int LOCATOR_ID { get; set; }//儲位ID
            public string SUBINVENTORY_CODE { get; set; }//倉庫
            public string SEGMENT1 { get; set; }//儲位架
            public string SEGMENT2 { get; set; }//儲位層
            public string SEGMENT3 { get; set; }//儲位
            public string PICKING_OUTER_ID { get; set; }//撿貨ID
            public string STD_KPCS { get; set; }//基本包裝量
            public string DELIVERY_QTY { get; set; }//出貨量
            public int REEL { get; set; }//卷數
            public string ATTRIBUTE1 { get; set; }//記錄唯一刷條碼
            public string ATTRIBUTE2 { get; set; }//記錄唯一刷條碼
            public string ATTRIBUTE3 { get; set; }//記錄唯一刷條碼
            public string ATTRIBUTE4 { get; set; }//記錄唯一刷條碼
            public string ATTRIBUTE5 { get; set; }//記錄唯一刷條碼
            public string ATTRIBUTE6 { get; set; }//記錄唯一刷條碼
            public string ATTRIBUTE7 { get; set; }//記錄唯一刷條碼
            public string ATTRIBUTE8 { get; set; }//記錄唯一刷條碼
            public string ATTRIBUTE9 { get; set; }//記錄唯一刷條碼
            public string ATTRIBUTE10 { get; set; }//記錄唯一刷條碼
            public string USER_ID { get; set; }//操作人員ID
            public string USER_NAME { get; set; }//操作人員
            public string CARD_NUM { get; set; }//工號
            public DateTime? CREATION_DATE { get; set; }//創建日期
            public DateTime? LAST_UPDATE { get; set; }//更新檢驗日期
            public string CUSTOMER_LOT { get; set; }//客戶批號
            public string PICKING_LINE_ID { get; set; }//客戶批號
            public string REEL_ID { get; set; }//客戶批號
            public string MANUAL_TYPE { get; set; }//客戶批號
            public string MANUAL_USER_ID { get; set; }//客戶批號
            public string MANUAL_DATE { get; set; }//客戶批號
            public string INNER_NUMBER { get; set; }//内盒号
            public string LOCK_STATUS { get; set; }//是否锁L為lock,  U為unlock
            public decimal? TotalREEL { get; set; }//
            public string REEL_UNIONList1 { get; set; }//不能重复扫的
            public string REEL_UNIONList2 { get; set; }//可以扫，但是要提示上架
        }

        public class RL_LOCATION_NUMBER_NAME_COUNT
        {
            public string NUMBER_DEL { get; set; }//撿貨列印碼
            public string OUTER_NUM { get; set; }//外箱號
            public string CARD_NUM { get; set; }//工號
            public string USER_ID { get; set; }//USER ID
            public DateTime? CREATION_DATE { get; set; }//建立日期
            public string REEL_NUM { get; set; }//卷數
            public string QTY { get; set; }//數量
            public string TYPE { get; set; }//O 類型O為撿貨下架, I為工單上架記錄時間
            public string Picking_line_id { get; set; }//rl_pda_pick_pulloff_s.nextval
            public string REEL_ID { get; set; }//唯一碼
            public string MANUAL_TYPE { get; set; }//默認Ｎ，Ｙ為移倉特殊情況人工檢查
            public string MANUAL_USER_ID { get; set; }//
            public string MANUAL_DATE { get; set; }//
            public string INNER_NUMBER { get; set; }//內盒號
            
        }

        public class Rl_PDA_Pick_pullOFF_detail
        {
            public string ORG_CODE { get; set; }//廠區
            public string DELIVERY_NAME { get; set; }//出貨單號
            public string OUTER_NUMBER { get; set; }//外箱
            public string INNER_NUMBER { get; set; }//内盒号
            public string PICKING_OUTER_ID { get; set; }//撿貨ID
            public string LOT_NUMBER { get; set; }//批號
            public string ITEM_NAME { get; set; }//料號
            public int LOCATOR_ID { get; set; }//儲位ID
            public string SUBINVENTORY_CODE { get; set; }//倉庫
            public string SEGMENT1 { get; set; }//儲位架
            public string SEGMENT2 { get; set; }//儲位層
            public string SEGMENT3 { get; set; }//儲位
            public int REEL { get; set; }//卷數
            public string REEL_ID { get; set; }//客戶批號
            public string PICKING_LINE_ID { get; set; }//客戶批號
            public string USER_ID { get; set; }//操作人員ID
            public DateTime? CREATION_DATE { get; set; }//創建日期
            public string LAST_USER_ID { get; set; }//操作人員ID
            public DateTime? LAST_UPDATE_DATE { get; set; }//更新檢驗日期
            public string ATTRIBUTE1 { get; set; }//記錄唯一刷條碼
            public string ATTRIBUTE2 { get; set; }//記錄唯一刷條碼
            public string ATTRIBUTE3 { get; set; }//記錄唯一刷條碼
            public string ATTRIBUTE4 { get; set; }//記錄唯一刷條碼
            public string CANCLE_FLAG { get; set; }//記錄唯一刷條碼
            public string JOIN_NUM { get; set; }//記錄唯一刷條碼
            public string DEL_REEL { get; set; }//物料類型:成品FG,散料STT
            public string BARCODE_UNION { get; set; }//客戶編號
        }

        //根据下架单获取详细信息
        [WebMethod]
        public List<rl_pda_pick_pulloff> Get_rl_pda_pick_pulloff_by_PRINT_CODE(string PRINT_CODE, string ORG_CODE)
        {
            WQEntities context = new WQEntities();
            List<rl_pda_pick_pulloff> List = new List<rl_pda_pick_pulloff>();
            try
            {
                var sqlResult = context.Database.SqlQuery<rl_pda_pick_pulloff>("select r.*,rowid from rl_pda_pick_pulloff r where r.ORG_CODE=" + ORG_CODE + " and r.PRINT_CODE='" + PRINT_CODE+"'");
                foreach (var order in sqlResult)
                {
                    rl_pda_pick_pulloff b = order;
                    List.Add(b);
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
            return List;
        }
        //获取下架單号
        [WebMethod]
        public List<string> Get_rl_pda_pick_pulloff_PRINT_CODE(string ORG_CODE)
        {
            WQEntities context = new WQEntities();
            List<string> List = new List<string>();
            try
            {
                var sqlResult = context.Database.SqlQuery<string>("select distinct PRINT_CODE from rl_pda_pick_pulloff where ORG_CODE=" + ORG_CODE);
                foreach (var order in sqlResult)
                {
                    List.Add(order);
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
            return List;
        }
        //下架.扫描下架
        [WebMethod]
        public string Update_rl_pda_pick_pulloff(string PRINT_CODE, int LOCATOR_ID, string REEL,string BQ, string REEL_UNION, string userid, string ORG_CODE)
        {
            WQEntities context = new WQEntities();
            WQEntities1 PDA = new WQEntities1();
            try
            {
                var menu = GetMenu(userid, ORG_CODE);
                if (menu.IndexOf("PDAF0002,") < 0)
                {
                    return "false:當前用戶沒有操作權限";
                }
                string NowDate = getTime();
                //先看下是否有人保存了数据，有的话就不让再保存
                //var nowvalue = PDA.pick_pulloff_record.FirstOrDefault(x => x.PRINT_CODE == PRINT_CODE && LOCATOR_ID==x.LOCATOR_ID && x.isDelete == false && x.State == true);
                //if (nowvalue != null)
                //    return "false:重複提交儲位";
                //else
                //{
                    int count = context.Database.ExecuteSqlCommand("UPDATE rl_pda_pick_pulloff SET RELEASE_LOC_FLAG  = 'C',USER_ID=:p0,LAST_UPDATE=:p1 WHERE RELEASE_LOC_FLAG  = 'Y' and PRINT_CODE=:p2 and LOCATOR_ID = :p3 and ORG_CODE = :p4", new[] { new OracleParameter(":p0", userid), new OracleParameter(":p1", NowDate), new OracleParameter(":p2", PRINT_CODE), new OracleParameter(":p3", LOCATOR_ID), new OracleParameter(":p4", ORG_CODE) });
                    var sqlResult = context.Database.SqlQuery<rl_pda_pick_pulloff>("select r.*,rowid from rl_pda_pick_pulloff r where r.PRINT_CODE='" + PRINT_CODE + "' and r.LOCATOR_ID=" + LOCATOR_ID + " and r.ORG_CODE=" + ORG_CODE);
                foreach (var b in sqlResult)
                    {
                        pick_pulloff_record v = new pick_pulloff_record();
                        v.ORG_CODE = b.ORG_CODE;
                        v.DELIVERY_NAME = b.DELIVERY_NAME;
                        v.PRINT_CODE = PRINT_CODE;
                        v.LOT_NUMBER = b.LOT_NUMBER;
                        v.ITEM_NAME = b.ITEM_NAME;
                        v.LOCATOR_ID = b.LOCATOR_ID;
                        v.SUBINVENTORY_CODE = b.SUBINVENTORY_CODE;
                        v.SEGMENT1 = b.SEGMENT1;
                        v.SEGMENT2 = b.SEGMENT2;
                        v.SEGMENT3 = b.SEGMENT3;
                        v.STD_KPCS = b.STD_KPCS;
                        v.DELIVERY_QTY = b.DELIVERY_QTY;
                        v.REEL = b.REEL;
                        v.ACTUAL_REEL = b.REEL;
                        v.BQ = BQ;
                        v.REEL_UNION=REEL_UNION;
                    v.CUSTOMER_LOT = b.CUSTOMER_LOT;
                    v.State = count >= 1 ? true : false;
                        v.isDelete = false;
                        v.creater = userid;
                        v.createTime = DateTime.Now;
                        v.updater = userid;
                        v.updateTime = DateTime.Now;
                        PDA.pick_pulloff_record.Add(v);
                    }
                    PDA.SaveChanges();
                    if (count >= 1)
                        return "true";
                    else
                        return "false:更新狀態失敗,請刷新頁面查看當前狀態";
                //}

            }
            catch (Exception ex)
            {
                HandleException(ex);
                return "false:执行错误";
            }
        }
        [WebMethod]
        public string Update_rl_pda_pick_pulloff_PL(string PRINT_CODE, string LOCATOR_IDs, string userid, string ORG_CODE)
        {
            WQEntities context = new WQEntities();
            WQEntities1 PDA = new WQEntities1();
            try
            {
                var menu = GetMenu(userid, ORG_CODE);
                if (menu.IndexOf("PDAF0002,") < 0)
                {
                    return "false:當前用戶沒有操作權限";
                }
                string NowDate = getTime();
                List<long?> LOCATOR_IDList = new List<long?>();
                foreach (var l in LOCATOR_IDs.Split(','))
                {
                    if (!string.IsNullOrEmpty(l))
                        LOCATOR_IDList.Add(long.Parse(l));
                }
                //先看下是否有人保存了数据，有的话就不让再保存
                //var nowvalue = PDA.pick_pulloff_record.FirstOrDefault(x => x.PRINT_CODE == PRINT_CODE && LOCATOR_IDList.Contains(x.LOCATOR_ID) && x.isDelete == false && x.State == true);
                //if (nowvalue != null)
                //    return "false:重複提交儲位";
                //else
                //{
                    int count = context.Database.ExecuteSqlCommand("UPDATE rl_pda_pick_pulloff SET RELEASE_LOC_FLAG  = 'C',USER_ID=" + userid + ",LAST_UPDATE='" + NowDate + "' WHERE PRINT_CODE='" + PRINT_CODE + "' and LOCATOR_ID in (" + LOCATOR_IDs.Substring(0, LOCATOR_IDs.Length - 1) + ") and ORG_CODE = " + ORG_CODE);
                var sqlResult = context.Database.SqlQuery<rl_pda_pick_pulloff>("select r.*,rowid from rl_pda_pick_pulloff r where r.RELEASE_LOC_FLAG  = 'Y' and r.PRINT_CODE='" + PRINT_CODE + "' and r.LOCATOR_ID in (" + LOCATOR_IDs.Substring(0, LOCATOR_IDs.Length - 1) + ") and r.ORG_CODE = " + ORG_CODE);
                foreach (var b in sqlResult)
                    {
                        pick_pulloff_record v = new pick_pulloff_record();
                        v.ORG_CODE = b.ORG_CODE;
                        v.DELIVERY_NAME = b.DELIVERY_NAME;
                        v.PRINT_CODE = PRINT_CODE;
                        v.LOT_NUMBER = b.LOT_NUMBER;
                        v.ITEM_NAME = b.ITEM_NAME;
                        v.LOCATOR_ID = b.LOCATOR_ID;
                        v.SUBINVENTORY_CODE = b.SUBINVENTORY_CODE;
                        v.SEGMENT1 = b.SEGMENT1;
                        v.SEGMENT2 = b.SEGMENT2;
                        v.SEGMENT3 = b.SEGMENT3;
                        v.STD_KPCS = b.STD_KPCS;
                        v.DELIVERY_QTY = b.DELIVERY_QTY;
                        v.REEL = b.REEL;
                        v.ACTUAL_REEL = b.REEL;
                    v.CUSTOMER_LOT = b.CUSTOMER_LOT;
                    v.State = count >= 1 ? true : false;
                        v.isDelete = false;
                        v.creater = userid;
                        v.createTime = DateTime.Now;
                        v.updater = userid;
                        v.updateTime = DateTime.Now;
                        PDA.pick_pulloff_record.Add(v);
                    }
                    PDA.SaveChanges();
                    if (count >= 1)
                        return "true";
                    else
                        return "false:更新狀態失敗,請刷新頁面查看當前狀態";
                //}

            }
            catch (Exception ex)
            {
                HandleException(ex);
                return "false:执行错误";
            }
        }

        [WebMethod]
        public List<rl_pda_pick_pulloff> Get_rl_pda_pick_pulloff_by_PRINT_CODEDB(string PRINT_CODE, string userid, string ORG_CODE)
        {
            WQEntities context = new WQEntities();
            string NowDate = getTime();
            List<rl_pda_pick_pulloff> List = new List<rl_pda_pick_pulloff>();
            try
            {
                var sqlResult = context.Database.SqlQuery<rl_pda_pick_pulloff>("select r.*,rowid from rl_pda_pick_pulloff r where r.ORG_CODE=" + ORG_CODE + " and r.PRINT_CODE='" + PRINT_CODE + "'");
                var sqlResult1 = context.Database.SqlQuery<Rl_PDA_Pick_pullOFF_detail>("select * from Rl_PDA_Pick_pullOFF_detail where DELIVERY_NAME=" + PRINT_CODE.Split('-')[0] + " and OUTER_NUMBER='" + PRINT_CODE.Split('-')[1] + "'");
                //省得判定，直接去查所有的，然后改状态
                //var JL = sqlResult1.Where(x => x.ATTRIBUTE4 == "Y" && x.CANCLE_FLAG == "Y").ToList();
                bool isxiugai = false;
                foreach (var d1 in sqlResult)
                {
                    if (d1.RELEASE_LOC_FLAG == "Y")
                    {
                        int count1 = sqlResult1.Where(x => x.PICKING_LINE_ID == d1.PICKING_LINE_ID && x.ATTRIBUTE4 == null && x.CANCLE_FLAG == "N").Count();
                        int count2 = sqlResult1.Where(x => x.PICKING_LINE_ID == d1.PICKING_LINE_ID && x.ATTRIBUTE4 == "Y" && x.CANCLE_FLAG == "N").Count();
                        if (count1 == d1.REEL && count2 == 0)
                        {
                            //修改状态
                            int count = context.Database.ExecuteSqlCommand("UPDATE rl_pda_pick_pulloff SET RELEASE_LOC_FLAG  = 'C',USER_ID=:p0,LAST_UPDATE=:p1 WHERE RELEASE_LOC_FLAG  = 'Y' and PRINT_CODE=:p2 and LOCATOR_ID = :p3 and ORG_CODE = :p4 and PICKING_LINE_ID=:p5", new[] { new OracleParameter(":p0", userid), new OracleParameter(":p1", NowDate), new OracleParameter(":p2", PRINT_CODE), new OracleParameter(":p3", d1.LOCATOR_ID), new OracleParameter(":p4", ORG_CODE), new OracleParameter(":p5", d1.PICKING_LINE_ID) });
                            if(count>=1)
                                isxiugai = true;
                        }
                    }
                }
                if(isxiugai)
                    sqlResult = context.Database.SqlQuery<rl_pda_pick_pulloff>("select r.*,rowid from rl_pda_pick_pulloff r where r.ORG_CODE=" + ORG_CODE + " and r.PRINT_CODE='" + PRINT_CODE + "'");

                //这里就只判断一下当前下架单的扫描记录吧，数据量太大了
                string REEL_UNIONList1 = "";
                string REEL_UNIONList2 = "";
                foreach (var detail in sqlResult1)
                {
                    //ATTRIBUTE4空，CANCLE_FLAG N已扫描
                    //ATTRIBUTE4 Y，CANCLE_FLAG N提示重新上架
                    //ATTRIBUTE4Y，CANCLE_FLAG Y已重新说上架，不用管
                    if (string.IsNullOrEmpty(detail.ATTRIBUTE4)&&detail.CANCLE_FLAG=="N")
                        REEL_UNIONList1 += detail.BARCODE_UNION + ",";
                    else if (detail.ATTRIBUTE4=="Y" && detail.CANCLE_FLAG == "N")
                        REEL_UNIONList2 += detail.BARCODE_UNION + ",";
                }
                    foreach (var order in sqlResult)
                {
                    rl_pda_pick_pulloff b = order;
                    b.TotalREEL = 0;
                    b.REEL_UNIONList1 = REEL_UNIONList1;
                    b.REEL_UNIONList2 = REEL_UNIONList2;
                    //Picking_line_id
                    //找到这条记录对应的所有扫描记录
                    var details = sqlResult1.Where(x =>x.PICKING_LINE_ID==order.PICKING_LINE_ID&& x.INNER_NUMBER == order.INNER_NUMBER && x.ATTRIBUTE4 == null && x.CANCLE_FLAG == "N").ToList();
                    if (details.Count > 0)
                        b.TotalREEL = details.Count();
                    List.Add(b);
                    
                } 
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
            return List;
        }
        [WebMethod]
        public string Update_rl_pda_pick_pulloffDB(string PRINT_CODE, int LOCATOR_ID, int INNER_NUMBER, List<BQView> BQList, string userid, string ORG_CODE)
        {
            WQEntities context = new WQEntities();
            WQEntities1 PDA = new WQEntities1();
            try
            {
                var menu = GetMenu(userid, ORG_CODE);
                if (menu.IndexOf("PDAF0002,") < 0)
                {
                    return "false:當前用戶沒有操作權限";
                }
                string NowDate = getTime();
                //先看下是否有人保存了数据，有的话就不让再保存
                string BQREEL_UNIONList = "";
                foreach (var b in BQList)
                {
                    BQREEL_UNIONList += ("'" + b.REEL_UNION + "',");
                }
                BQREEL_UNIONList = BQREEL_UNIONList.Substring(0, BQREEL_UNIONList.Length - 1);
                var sqlResult1 = context.Database.SqlQuery<Rl_PDA_Pick_pullOFF_detail>("select * from Rl_PDA_Pick_pullOFF_detail where ATTRIBUTE4 is null and CANCLE_FLAG = 'N' and BARCODE_UNION in （" + BQREEL_UNIONList + ")");
                if (sqlResult1.Count() > 0)
                {
                    string cf = "";
                    foreach (var n in sqlResult1)
                        cf += n.BARCODE_UNION + ";";
                    return "false:重複提交标签：" + cf;
                }
                else
                {
                    //查到当前所有未完成的单子
                    var sqlResult2 = context.Database.SqlQuery<rl_pda_pick_pulloff>("select r.*,rowid from rl_pda_pick_pulloff r where r.RELEASE_LOC_FLAG  = 'Y' and r.PRINT_CODE='" + PRINT_CODE + "' and r.INNER_NUMBER=" + INNER_NUMBER + " and r.LOCATOR_ID=" + LOCATOR_ID + " and r.ORG_CODE=" + ORG_CODE);
                    if (sqlResult2.Count() <= 0)
                        return "false:請刷新頁面查看當前狀態";
                    rl_pda_pick_pulloff b = sqlResult2.First();
                    decimal? total = BQList.Count();
                    int count = 0;
                        decimal YSM = 0;
                        //获取当前单子已经扫描的卷数
                        var sqlResult3 = context.Database.SqlQuery<Rl_PDA_Pick_pullOFF_detail>("select * from Rl_PDA_Pick_pullOFF_detail where ATTRIBUTE4 is null and CANCLE_FLAG = 'N' and PICKING_LINE_ID=" + b.PICKING_LINE_ID + " and DELIVERY_NAME=" + PRINT_CODE.Split('-')[0] + " and OUTER_NUMBER='" + PRINT_CODE.Split('-')[1] + "'");
                        if (sqlResult3.Count() > 0)
                            YSM = sqlResult3.Count();
                        //这里要判定下当前扫描的数量，足够，就去修改状态，否则不改
                        if (total == (b.REEL - YSM))
                        {
                            count = context.Database.ExecuteSqlCommand("UPDATE rl_pda_pick_pulloff SET RELEASE_LOC_FLAG  = 'C',USER_ID=:p0,LAST_UPDATE=:p1 WHERE RELEASE_LOC_FLAG  = 'Y' and PRINT_CODE=:p2 and LOCATOR_ID = :p3 and ORG_CODE = :p4 and PICKING_LINE_ID=:p5", new[] { new OracleParameter(":p0", userid), new OracleParameter(":p1", NowDate), new OracleParameter(":p2", PRINT_CODE), new OracleParameter(":p3", LOCATOR_ID), new OracleParameter(":p4", ORG_CODE), new OracleParameter(":p5", b.PICKING_LINE_ID) });
                            if (count == 0)
                                return "false:更新狀態失敗,請刷新頁面查看當前狀態";
                        }
                        //插入数据
                        foreach (var bq in BQList)
                        {
                            count = context.Database.ExecuteSqlCommand("INSERT INTO Rl_PDA_Pick_pullOFF_detail( ORG_CODE,DELIVERY_NAME,OUTER_NUMBER,INNER_NUMBER,PICKING_OUTER_ID,LOT_NUMBER,ITEM_NAME,LOCATOR_ID,SUBINVENTORY_CODE,SEGMENT1,SEGMENT2,SEGMENT3,REEL,REEL_ID,PICKING_LINE_ID,USER_ID,CREATION_DATE,LAST_USER_ID,LAST_UPDATE_DATE,ATTRIBUTE1,ATTRIBUTE2,ATTRIBUTE3,CANCLE_FLAG,JOIN_NUM,BARCODE_UNION) values(:p1,:p2,:p3,:p4,:p5,:p6,:p7,:p8,:p9,:p10,:p11,:p12,:p13,:p14,:p15,:p16,:p17,:p18,:p19,:p20,:p21,:p22,:p23,:p24,:p25)",
                             //  , ATTRIBUTE1, ATTRIBUTE2, ATTRIBUTE3, JOIN_NUM, DEL_REEL, BARCODE_UNION
                                new[] { new OracleParameter(":p1", b.ORG_CODE), new OracleParameter(":p2", b.DELIVERY_NAME),
                 new OracleParameter(":p3", b.OUTER_NUMBER), new OracleParameter(":p4", b.INNER_NUMBER),
                  new OracleParameter(":p5", b.PICKING_OUTER_ID), new OracleParameter(":p6", b.LOT_NUMBER),
                   new OracleParameter(":p7", b.ITEM_NAME), new OracleParameter(":p8", b.LOCATOR_ID),
                    new OracleParameter(":p9", b.SUBINVENTORY_CODE), new OracleParameter(":p10", b.SEGMENT1),
                    new OracleParameter(":p11", b.SEGMENT2), new OracleParameter(":p12", b.SEGMENT3),
                    new OracleParameter(":p13", b.REEL), new OracleParameter(":p14", bq.BQ),
                    new OracleParameter(":p15", b.PICKING_LINE_ID), new OracleParameter(":p16", userid),
                     new OracleParameter(":p17", NowDate), new OracleParameter(":p18", userid),
                      new OracleParameter(":p19", NowDate), new OracleParameter(":p20", b.ATTRIBUTE1),
                       new OracleParameter(":p21", b.ATTRIBUTE2), new OracleParameter(":p22", b.ATTRIBUTE3),
                       new OracleParameter(":p23", "N"), new OracleParameter(":p24", b.PICKING_OUTER_ID+'-'+b.OUTER_NUMBER+'-'+b.INNER_NUMBER+'-'+b.LOCATOR_ID),
                       new OracleParameter(":p25", bq.REEL_UNION)});
                            //这里应该不用再去判定当前库位是否在这个盘点单子里了，前台就判定好
                            if (count > 0)
                            {
                                pick_pulloff_record v = new pick_pulloff_record();
                                v.ORG_CODE = b.ORG_CODE;
                                v.DELIVERY_NAME = b.DELIVERY_NAME;
                                v.PRINT_CODE = PRINT_CODE;
                                v.LOT_NUMBER = b.LOT_NUMBER;
                                v.ITEM_NAME = b.ITEM_NAME;
                                v.LOCATOR_ID = b.LOCATOR_ID;
                                v.SUBINVENTORY_CODE = b.SUBINVENTORY_CODE;
                                v.SEGMENT1 = b.SEGMENT1;
                                v.SEGMENT2 = b.SEGMENT2;
                                v.SEGMENT3 = b.SEGMENT3;
                                v.STD_KPCS = b.STD_KPCS;
                                v.DELIVERY_QTY = b.DELIVERY_QTY;
                                v.REEL = b.REEL;
                                v.ACTUAL_REEL = 1;
                                v.BQ = bq.BQ;
                                v.REEL_UNION = bq.REEL_UNION;
                                v.CUSTOMER_LOT = b.CUSTOMER_LOT;
                                v.State = true;
                                v.isDelete = false;
                                v.creater = userid;
                                v.createTime = DateTime.Now;
                                v.updater = userid;
                                v.updateTime = DateTime.Now;
                                PDA.pick_pulloff_record.Add(v);
                            }
                        }
                    PDA.SaveChanges();
                    return "true";
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
                return "false:执行错误";
            }
        }

        [WebMethod]
        public string Update_rl_pda_pick_pulloff_LOCK_STATUS(string PRINT_CODE,string LOCK_STATUS, string userid, string ORG_CODE)
        {
            WQEntities context = new WQEntities();
            List<rl_pda_pick_pulloff> List = new List<rl_pda_pick_pulloff>();
            try
            {
                string NowDate = getTime();
                int count = context.Database.ExecuteSqlCommand("UPDATE rl_pda_pick_pulloff SET LOCK_STATUS  = :p0,USER_ID=:p1,LAST_UPDATE=:p2 WHERE  PRINT_CODE=:p3 and ORG_CODE = :p4", new[] { new OracleParameter(":p0", LOCK_STATUS), new OracleParameter(":p1", userid), new OracleParameter(":p2", NowDate), new OracleParameter(":p3", PRINT_CODE), new OracleParameter(":p4", ORG_CODE) });
                if (count > 0)
                    return "true";
                else
                    return "false";
            }
            catch (Exception ex)
            {
                HandleException(ex);
                return "false";
            }
        }

        public class RL_INVENTORY_SCHEDULE_LINES
        {
            public string ORG_CODE { get; set; }//
            public string PI_CODE { get; set; }//
            public string SLOC { get; set; }//
            public string LOC1_FM { get; set; }//
            public string LOC2_FM { get; set; }//
            public string LOC3_FM { get; set; }//
            public string LOC1_TO { get; set; }//
            public string LOC2_TO { get; set; }//
            public string LOC3_TO { get; set; }//

            public string LAST_UPDATE_DATE { get; set; }//外箱號
            public string LAST_UPDATED_BY { get; set; }//工號
            public string CREATION_DATE { get; set; }//USER ID
            public string CREATED_BY { get; set; }//建立日期
            public string REEL_UNIONList { get; set; }//
        }
        public class RL_INV_SCH_SCAN_LINES
        {
            public string ORG_CODE { get; set; }//
            public string PI_CODE { get; set; }//
            public string SLOC { get; set; }//
            public string LOC1 { get; set; }//
            public string LOC2 { get; set; }//
            public string LOC3 { get; set; }//
            public string ITEM_NAME { get; set; }//
            public string LOT_NUMBER { get; set; }//
            public string REEL_ID { get; set; }//
            public double REEL_QTY { get; set; }//

            public string LAST_UPDATE_DATE { get; set; }//外箱號
            public string LAST_UPDATED_BY { get; set; }//工號
            public string CREATION_DATE { get; set; }//USER ID
            public DateTime? CREATED_BY { get; set; }//建立日期
            public string REEL_NUMBER { get; set; }//
            public string REEL_UNION { get; set; }//
            public string CUSTOMER_LOT { get; set; }//
        }
        public class RL_INVENTORY_SCHEDULE_ONHAND
        {
            public string ORG_CODE { get; set; }//
            public string PI_CODE { get; set; }//
            public string SLOC { get; set; }//
            public string LOC1 { get; set; }//
            public string LOC2 { get; set; }//
            public string LOC3 { get; set; }//
            public string ITEM_NAME { get; set; }//
            public string LOT_NUMBER { get; set; }//
            public string ONHAND_QTY { get; set; }//
            public string LAST_UPDATE_DATE { get; set; }//
            public string LAST_UPDATED_BY { get; set; }//
            public string CREATION_DATE { get; set; }//
            public string CREATED_BY { get; set; }//
            public string REEL_NUMBER { get; set; }//
        }

        //根据盘点单获取详细信息
        [WebMethod]
        public List<RL_INVENTORY_SCHEDULE_LINES> Get_RL_INVENTORY_SCHEDULE_LINES_by_PI_CODE(string PI_CODE, string ORG_CODE)
        {
            WQEntities context = new WQEntities();
            List<RL_INVENTORY_SCHEDULE_LINES> List = new List<RL_INVENTORY_SCHEDULE_LINES>();
            try
            {
                var sqlResult = context.Database.SqlQuery<RL_INVENTORY_SCHEDULE_LINES>("select r.*,rowid from RL_INVENTORY_SCHEDULE_LINES r where r.ORG_CODE=" + ORG_CODE + " and r.PI_CODE='" + PI_CODE + "'");
                foreach (var order in sqlResult)
                {
                    RL_INVENTORY_SCHEDULE_LINES b = order;
                    List.Add(b);
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
            return List;
        }
        //获取盘点單号
        [WebMethod]
        public List<string> Get_RL_INVENTORY_SCHEDULE_LINES_PRINT_CODE(string ORG_CODE)
        {
            WQEntities context = new WQEntities();
            List<string> List = new List<string>();
            try
            {
                var sqlResult = context.Database.SqlQuery<string>("select distinct PI_CODE from RL_INVENTORY_SCHEDULE_LINES where ORG_CODE=" + ORG_CODE);
                foreach (var order in sqlResult)
                {
                    List.Add(order);
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
            return List;
        }
        //获取储位信息
        [WebMethod]
        public RL_INVENTORY_SCHEDULE_ONHAND Get_RL_INVENTORY_SCHEDULE_ONHAND(string LOC1,string LOC2,string LOC3, string ORG_CODE)
        {
            WQEntities context = new WQEntities();
            List<string> List = new List<string>();
            RL_INVENTORY_SCHEDULE_ONHAND r = new RL_INVENTORY_SCHEDULE_ONHAND();
            try
            {
                var sqlResult = context.Database.SqlQuery<RL_INVENTORY_SCHEDULE_ONHAND>("select *  from RL_INVENTORY_SCHEDULE_ONHAND where LOC1='" + LOC1+ "' and LOC2='" + LOC2+ "' and LOC3 = '" + LOC3+ "' and ORG_CODE = " + ORG_CODE);
                foreach (var order in sqlResult)
                {
                    r = order;
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
            return r;
        }
        //插入盘点数据
        [WebMethod]
        public string Insert_RL_INV_SCH_SCAN_LINES(INVENTORY_SCHEDULE_LINES_record data, string userid)
        {
            WQEntities context = new WQEntities();
            WQEntities1 PDA = new WQEntities1();
            try
            {
                var menu = GetMenu(userid, "");
                if (menu.IndexOf("PDAF0003,") < 0)
                {
                    return "false:當前用戶沒有操作權限";
                }
                //先看下是否有人保存了数据，有的话就不让再保存
                var nowvalue = PDA.INVENTORY_SCHEDULE_LINES_record.FirstOrDefault(x => x.PI_CODE == data.PI_CODE && x.SLOC == data.SLOC && x.LOC1 == data.LOC1 && x.LOC2 == data.LOC2 && x.LOC3 == data.LOC3&&x.isDelete==false&&x.State==true);
                if (nowvalue != null)
                    return "false:重複提交儲位";
                else
                {
                    //data.ORG_CODE = "8281";
                    string NowDate = getTime();
                    int count = context.Database.ExecuteSqlCommand("INSERT INTO RL_INV_SCH_SCAN_LINES(ORG_CODE,PI_CODE,SLOC,LOC1,LOC2,LOC3,ITEM_NAME,LOT_NUMBER,REEL_ID,REEL_QTY,LAST_UPDATE_DATE,LAST_UPDATED_BY,CREATION_DATE,CREATED_BY,REEL_NUMBER,REEL_UNION,CUSTOMER_LOT) values(:p1,:p2,:p3,:p4,:p5,:p6,:p7,:p8,:p9,:p10,:p11,:p12,:p13,:p14,:p15,:p16,:p17)",
                        new[] { new OracleParameter(":p1", data.ORG_CODE), new OracleParameter(":p2", data.PI_CODE),
                 new OracleParameter(":p3", data.SLOC), new OracleParameter(":p4", data.LOC1),
                  new OracleParameter(":p5", data.LOC2), new OracleParameter(":p6", data.LOC3),
                   new OracleParameter(":p7", data.ITEM_NAME), new OracleParameter(":p8", data.LOT_NUMBER),
                    new OracleParameter(":p9", data.REEL_ID), new OracleParameter(":p10", data.REEL_QTY),
                     new OracleParameter(":p11", NowDate), new OracleParameter(":p12", userid),
                new OracleParameter(":p13", NowDate), new OracleParameter(":p14", userid),
                new OracleParameter(":p15", data.REEL_QTY), new OracleParameter(":p16", data.REEL_UNION), new OracleParameter(":p17", data.CUSTOMER_LOT)});
                    //这里应该不用再去判定当前库位是否在这个盘点单子里了，前台就判定好

                        INVENTORY_SCHEDULE_LINES_record v = new INVENTORY_SCHEDULE_LINES_record();
                        v.ORG_CODE = data.ORG_CODE;
                        v.PI_CODE = data.PI_CODE;
                        v.LOT_NUMBER = data.LOT_NUMBER;
                        v.ITEM_NAME = data.ITEM_NAME;
                        v.SLOC = data.SLOC;
                        v.LOC1 = data.LOC1;
                        v.LOC2 = data.LOC2;
                        v.LOC3 = data.LOC3;
                        v.REEL_ID = data.REEL_ID;
                        v.REEL_QTY = data.REEL_QTY;
                        v.BQ = data.BQ;
                        v.REEL_UNION = data.REEL_UNION;
                        v.CUSTOMER_LOT = data.CUSTOMER_LOT;
                        v.State = count >= 1 ? true : false;
                        v.isDelete = false;
                        v.creater = userid;
                        v.createTime = DateTime.Now;
                        v.updater = userid;
                        v.updateTime = DateTime.Now;
                        PDA.INVENTORY_SCHEDULE_LINES_record.Add(v);
                    
                    PDA.SaveChanges();
                    if (count >= 1)
                        return "true";
                    else
                        return "false:插入數據失敗";
                }

            }
            catch (Exception ex)
            {
                HandleException(ex);
                return "false:执行错误";
            }
        }
        [WebMethod]
        public List<RL_INVENTORY_SCHEDULE_LINES> Get_RL_INVENTORY_SCHEDULE_LINES_by_PI_CODEDB(string PI_CODE, string ORG_CODE)
        {
            WQEntities context = new WQEntities();
            WQEntities1 PDA = new WQEntities1();
            List<RL_INVENTORY_SCHEDULE_LINES> List = new List<RL_INVENTORY_SCHEDULE_LINES>();
            try
            {
                var sqlResult = context.Database.SqlQuery<RL_INVENTORY_SCHEDULE_LINES>("select r.*,rowid from RL_INVENTORY_SCHEDULE_LINES r where r.ORG_CODE=" + ORG_CODE + " and r.PI_CODE='" + PI_CODE + "'");
                foreach (var order in sqlResult)
                {
                    RL_INVENTORY_SCHEDULE_LINES b = order;
                    b.REEL_UNIONList = "";
                    var record = PDA.INVENTORY_SCHEDULE_LINES_record.Where(x => x.PI_CODE == order.PI_CODE  && x.isDelete == false && x.State == true).ToList();
                    foreach (var r in record)
                    {
                        b.REEL_UNIONList += r.REEL_UNION + ",";
                    }
                    List.Add(b);
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
            return List;
        }
        [WebMethod]
        public string Insert_RL_INV_SCH_SCAN_LINESDB(List<INVENTORY_SCHEDULE_LINES_record> datas, string userid)
        {
            WQEntities context = new WQEntities();
            WQEntities1 PDA = new WQEntities1();
            try
            {
                var menu = GetMenu(userid, "");
                if (menu.IndexOf("PDAF0003,") < 0)
                {
                    return "false:當前用戶沒有操作權限";
                }
                //先看下是否有人保存了数据，有的话就不让再保存
                List<string> BQREEL_UNIONList = datas.Select(x => x.REEL_UNION).ToList();
                string PI_CODE = datas[0].PI_CODE;
                var nowvalue = PDA.INVENTORY_SCHEDULE_LINES_record.Where(x => x.PI_CODE == PI_CODE&& BQREEL_UNIONList.Contains(x.REEL_UNION) && x.isDelete == false && x.State == true).ToList();
                if (nowvalue.Count > 0)
                {
                    string cf = "";
                    foreach (var n in nowvalue)
                        cf += n.REEL_UNION + ";";
                    return "false:重複提交标签：" + cf;
                }
                else
                {
                    string NowDate = getTime();
                    string error = "";
                    foreach (var data in datas)
                    {
                        int count = context.Database.ExecuteSqlCommand("INSERT INTO RL_INV_SCH_SCAN_LINES(ORG_CODE,PI_CODE,SLOC,LOC1,LOC2,LOC3,ITEM_NAME,LOT_NUMBER,REEL_ID,REEL_QTY,LAST_UPDATE_DATE,LAST_UPDATED_BY,CREATION_DATE,CREATED_BY,REEL_NUMBER,REEL_UNION,CUSTOMER_LOT) values(:p1,:p2,:p3,:p4,:p5,:p6,:p7,:p8,:p9,:p10,:p11,:p12,:p13,:p14,:p15,:p16,:p17)",
                            new[] { new OracleParameter(":p1", data.ORG_CODE), new OracleParameter(":p2", data.PI_CODE),
                 new OracleParameter(":p3", data.SLOC), new OracleParameter(":p4", data.LOC1),
                  new OracleParameter(":p5", data.LOC2), new OracleParameter(":p6", data.LOC3),
                   new OracleParameter(":p7", data.ITEM_NAME), new OracleParameter(":p8", data.LOT_NUMBER),
                    new OracleParameter(":p9", data.REEL_ID), new OracleParameter(":p10", data.REEL_QTY),
                     new OracleParameter(":p11", NowDate), new OracleParameter(":p12", userid),
                new OracleParameter(":p13", NowDate), new OracleParameter(":p14", userid),
                new OracleParameter(":p15", data.REEL_QTY), new OracleParameter(":p16", data.REEL_UNION), new OracleParameter(":p17", data.CUSTOMER_LOT)});
                        //这里应该不用再去判定当前库位是否在这个盘点单子里了，前台就判定好
                        if (count > 0)
                        {
                            INVENTORY_SCHEDULE_LINES_record v = new INVENTORY_SCHEDULE_LINES_record();
                            v.ORG_CODE = data.ORG_CODE;
                            v.PI_CODE = data.PI_CODE;
                            v.LOT_NUMBER = data.LOT_NUMBER;
                            v.ITEM_NAME = data.ITEM_NAME;
                            v.SLOC = data.SLOC;
                            v.LOC1 = data.LOC1;
                            v.LOC2 = data.LOC2;
                            v.LOC3 = data.LOC3;
                            v.REEL_ID = data.REEL_ID;
                            v.REEL_QTY = data.REEL_QTY;
                            v.BQ = data.BQ;
                            v.REEL_UNION = data.REEL_UNION;
                            v.CUSTOMER_LOT = data.CUSTOMER_LOT;
                            v.State = true;
                            v.isDelete = false;
                            v.creater = userid;
                            v.createTime = DateTime.Now;
                            v.updater = userid;
                            v.updateTime = DateTime.Now;
                            PDA.INVENTORY_SCHEDULE_LINES_record.Add(v);
                        }
                    }

                    PDA.SaveChanges();
                    if(error=="")
                        return "true";
                    else
                        return "false:插入數據失敗"+error;
                }

            }
            catch (Exception ex)
            {
                HandleException(ex);
                return "false:执行错误";
            }
        }
        [WebMethod]
        public string Get_REELandCUSTOMER_LOT(string PI_CODE, string KW, string ORG_CODE)
        {
            WQEntities1 db = new WQEntities1();
            string LOC1 = "";
            string LOC2 = "";
            string LOC3 = "";
            if (!string.IsNullOrEmpty(KW))
            {
                LOC1 = KW.Split('-')[0];
                LOC2 = KW.Split('-')[1];
                LOC3 = KW.Split('-')[2];
            }
            List<INVENTORY_SCHEDULE_LINES_record> ms = new List<INVENTORY_SCHEDULE_LINES_record>();
            var query = db.INVENTORY_SCHEDULE_LINES_record.AsQueryable();
            query = query.Where(m => m.ORG_CODE == ORG_CODE);
            if (!string.IsNullOrEmpty(PI_CODE))
                query = query.Where(m => m.PI_CODE == PI_CODE);
            if (!string.IsNullOrEmpty(KW))
                query = query.Where(m => m.LOC1 == LOC1 && m.LOC2 == LOC2 && m.LOC3 == LOC3);
            ms = query.OrderBy(x => x.isDelete).ThenByDescending(x => x.createTime).ToList();
            if (ms.Count() == 0)
                return "";
            else
                return ms.Sum(x => x.REEL_QTY) + "," + ms.First().LOT_NUMBER;
        }
        public string getTime()
        {
            DateTime date = DateTime.Now;

            // 创建DateTimeFormatInfo对象，设置月份为汉字形式
            DateTimeFormatInfo dtfi = new DateTimeFormatInfo();
            dtfi.MonthNames = new string[] {
            string.Empty, "一月", "二月", "三月", "四月", "五月", "六月",
            "七月", "八月", "九月", "十月", "十一月", "十二月" };
            dtfi.AbbreviatedMonthNames = new string[] {
            string.Empty, "1月", "2月", "3月", "4月", "5月", "6月",
            "7月", "8月", "9月", "10月", "11月", "12月" };
            dtfi.MonthGenitiveNames = new string[] {
            string.Empty, "一月", "二月", "三月", "四月", "五月", "六月",
            "七月", "八月", "九月", "十月", "十一月", "十二月" };
            dtfi.AbbreviatedMonthGenitiveNames = new string[] {
            string.Empty, "1月", "2月", "3月", "4月", "5月", "6月",
            "7月", "8月", "9月", "10月", "11月", "12月" };

            // 使用自定义的DateTimeFormatInfo来格式化日期
            string formattedDate = date.ToString("dd-M月 -yyyy", dtfi);
            string formattedDate1 = date.ToString("dd-M月 -yy", dtfi);
            return formattedDate1;
        }

        //获取记录
        [WebMethod]
        public List<wip_to_inv_record> getwip_to_inv_recordList(string LOCATION_NUMBER, string ORG_CODE ,string KW, int pageIndex, int size)
        {
            WQEntities1 db = new WQEntities1();
            string LOC1 = "";
            string LOC2 = "";
            string LOC3 = "";
            if (!string.IsNullOrEmpty(KW))
            {
                LOC1 = KW.Split('-')[0];
                LOC2 = KW.Split('-')[1];
                LOC3 = KW.Split('-')[2];
            }
            List<wip_to_inv_record> ms = new List<wip_to_inv_record>();
                 var query = db.wip_to_inv_record.AsQueryable();
            query = query.Where(m => m.ORG_CODE == ORG_CODE);
            if (!string.IsNullOrEmpty(LOCATION_NUMBER))
                    query = query.Where(m => m.LOCATION_NUMBER==LOCATION_NUMBER);
                if (!string.IsNullOrEmpty(KW))
                    query = query.Where(m => m.SEGMENT1 == LOC1&& m.SEGMENT2 == LOC2 && m.SEGMENT3 == LOC3 );
                ms = query.OrderBy(x=>x.isDelete).ThenByDescending(x => x.createTime).Skip((pageIndex - 1) * size).Take(size).ToList();

            int c = 0;
            var query1 = db.wip_to_inv_record.AsQueryable();
            if (!string.IsNullOrEmpty(LOCATION_NUMBER))
                query1 = query.Where(m => m.LOCATION_NUMBER == LOCATION_NUMBER);
            if (!string.IsNullOrEmpty(KW))
                query1 = query.Where(m => m.SEGMENT1 == LOC1 && m.SEGMENT2 == LOC2 && m.SEGMENT3 == LOC3);
            c = query1.Count();
            db.Dispose();
            if (ms.Count > 0)
                ms.First().updater = c.ToString();
            return ms;
        }
        [WebMethod]
        public string Delwip_to_inv_record(long id, string userid)
        {
            WQEntities1 db = new WQEntities1();
            var w = db.wip_to_inv_record.FirstOrDefault(x => x.ID == id&&x.isDelete==false);
            if (w != null)
            {
                w.updater = userid;
                w.updateTime = DateTime.Now;
                w.isDelete = true;
                db.SaveChanges();
                db.Dispose();
                return "true";
            }
            else
                return "false";
            
           
        }
        [WebMethod]
        public List<pick_pulloff_record> getpick_pulloff_recordList(string PRINT_CODE, string ORG_CODE, string KW, int pageIndex, int size)
        {
            WQEntities1 db = new WQEntities1();
            string LOC1 = "";
            string LOC2 = "";
            string LOC3 = "";
            if (!string.IsNullOrEmpty(KW))
            {
                LOC1 = KW.Split('-')[0];
                LOC2 = KW.Split('-')[1];
                LOC3 = KW.Split('-')[2];
            }
            List<pick_pulloff_record> ms = new List<pick_pulloff_record>();
            var query = db.pick_pulloff_record.AsQueryable();
            query = query.Where(m => m.ORG_CODE == ORG_CODE);
            if (!string.IsNullOrEmpty(PRINT_CODE))
                query = query.Where(m => m.PRINT_CODE == PRINT_CODE);
            if (!string.IsNullOrEmpty(KW))
                query = query.Where(m => m.SEGMENT1 == LOC1 && m.SEGMENT2 == LOC2 && m.SEGMENT3 == LOC3);
            ms = query.OrderBy(x => x.isDelete).ThenByDescending(x => x.createTime).Skip((pageIndex - 1) * size).Take(size).ToList();

            int c = 0;
            var query1 = db.pick_pulloff_record.AsQueryable();
            if (!string.IsNullOrEmpty(PRINT_CODE))
                query1 = query.Where(m => m.PRINT_CODE == PRINT_CODE);
            if (!string.IsNullOrEmpty(KW))
                query1 = query.Where(m => m.SEGMENT1 == LOC1 && m.SEGMENT2 == LOC2 && m.SEGMENT3 == LOC3);
            c = query1.Count();
            db.Dispose();
            if (ms.Count > 0)
                ms.First().updater = c.ToString();
            return ms;
        }
        [WebMethod]
        public string Delpick_pulloff_record(long id, string userid)
        {
            WQEntities1 db = new WQEntities1();
            var w = db.pick_pulloff_record.FirstOrDefault(x => x.ID == id && x.isDelete == false);
            if (w != null)
            {
                w.updater = userid;
                w.updateTime = DateTime.Now;
                w.isDelete = true;
                db.SaveChanges();
                db.Dispose();
                return "true";
            }
            else
                return "false";


        }
        [WebMethod]
        public List<INVENTORY_SCHEDULE_LINES_record> getINVENTORY_SCHEDULE_LINES_recordList(string PI_CODE, string ORG_CODE, string KW, int pageIndex, int size)
        {
            WQEntities1 db = new WQEntities1();
            string LOC1 = "";
            string LOC2 = "";
            string LOC3 = "";
            if (!string.IsNullOrEmpty(KW))
            {
                LOC1 = KW.Split('-')[0];
                LOC2 = KW.Split('-')[1];
                LOC3 = KW.Split('-')[2];
            }
            List<INVENTORY_SCHEDULE_LINES_record> ms = new List<INVENTORY_SCHEDULE_LINES_record>();
            var query = db.INVENTORY_SCHEDULE_LINES_record.AsQueryable();
            query = query.Where(m => m.ORG_CODE == ORG_CODE);
            if (!string.IsNullOrEmpty(PI_CODE))
                query = query.Where(m => m.PI_CODE == PI_CODE);
            if (!string.IsNullOrEmpty(KW))
                query = query.Where(m => m.LOC1 == LOC1 && m.LOC2 == LOC2 && m.LOC3 == LOC3);
            ms = query.OrderBy(x => x.isDelete).ThenByDescending(x => x.createTime).Skip((pageIndex - 1) * size).Take(size).ToList();

            int c = 0;
            var query1 = db.INVENTORY_SCHEDULE_LINES_record.AsQueryable();
            if (!string.IsNullOrEmpty(PI_CODE))
                query1 = query.Where(m => m.PI_CODE == PI_CODE);
            if (!string.IsNullOrEmpty(KW))
                query1 = query.Where(m => m.LOC1 == LOC1 && m.LOC2 == LOC2 && m.LOC3 == LOC3);
            c = query1.Count();
            db.Dispose();
            if (ms.Count > 0)
                ms.First().updater = c.ToString();
            return ms;
        }
        [WebMethod]
        public string DelINVENTORY_SCHEDULE_LINES_record(long id, string userid)
        {
            WQEntities1 db = new WQEntities1();
            var w = db.INVENTORY_SCHEDULE_LINES_record.FirstOrDefault(x => x.ID == id && x.isDelete == false);
            if (w != null)
            {
                w.updater = userid;
                w.updateTime = DateTime.Now;
                w.isDelete = true;
                db.SaveChanges();
                db.Dispose();
                return "true";
            }
            else
                return "false";


        }
        [WebMethod]
        public string GetMenu(string userid, string ORG_CODE)
        {
            WQEntities context = new WQEntities();
            string menusid = "";
            try
            {
                var sqlResult = context.Database.SqlQuery<string>("select  rr.FUNCTION_CODE from rl_pda_user ss, rl_user_function_v rr where ss.user_id = rr.USER_ID AND RR.FUNCTION_GROUP1 = 'PDA' AND ss.start_date <= sysdate AND(ss.end_date is null or ss.end_date > sysdate) and ss.user_id=" + userid);
                foreach (var order in sqlResult)
                {
                    menusid += order + ',';
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
            return menusid;

        }
        public class RL_PDA_LOT_V
        {
            public string ITEM_NAME { get; set; }//
            public string LOT_NUMBER { get; set; }//
            public string CUSTOMER_LOT { get; set; }//
        }
        [WebMethod]
        public List<RL_PDA_LOT_V> GetITEM_NAME_LOT_NUMBER_CUSTOMER_LOT(string ITEM_NAME, string LOT_NUMBER,string CUSTOMER_LOT)
        {
            WQEntities context = new WQEntities();
            List<RL_PDA_LOT_V> b = new List<RL_PDA_LOT_V>();
            try
            {
                if (!string.IsNullOrEmpty(ITEM_NAME))
                {
                    var sqlResult = context.Database.SqlQuery<RL_PDA_LOT_V>("select * from RL_PDA_LOT_V where ITEM_NAME='" + ITEM_NAME+"'");
                    foreach (var order in sqlResult)
                    {
                        b.Add(order);
                    }
                }
                else if (!string.IsNullOrEmpty(LOT_NUMBER))
                {
                    var sqlResult = context.Database.SqlQuery<RL_PDA_LOT_V>("select * from RL_PDA_LOT_V where LOT_NUMBER='" + LOT_NUMBER + "'");
                    foreach (var order in sqlResult)
                    {
                        b.Add(order);
                    }
                }
                else if (!string.IsNullOrEmpty(CUSTOMER_LOT))
                {
                    var sqlResult = context.Database.SqlQuery<RL_PDA_LOT_V>("select * from RL_PDA_LOT_V where CUSTOMER_LOT='" + CUSTOMER_LOT + "'");
                    foreach (var order in sqlResult)
                    {
                        b.Add(order);
                    }
                }
                return b;
            }
            catch (Exception ex)
            {
                HandleException(ex);
                return b;
            }
        }
    }
}
